Add site-wide options to disable all e-mail functions or only user-to-user email.
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2
3 /**
4 *
5 * @package MediaWiki
6 * @subpackage Skins
7 */
8
9 /**
10 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
11 */
12 if( defined( "MEDIAWIKI" ) ) {
13
14 # See skin.doc
15 require_once( 'Image.php' );
16
17 # Get a list of all skins available in /skins/
18 # Build using the regular expression '^(.*).php$'
19 # Array keys are all lower case, array value keep the case used by filename
20 #
21
22 $skinDir = dir($IP.'/skins');
23
24 # while code from www.php.net
25 while (false !== ($file = $skinDir->read())) {
26 if(preg_match('/^(.*).php$/',$file, $matches)) {
27 $aSkin = $matches[1];
28 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
29 }
30 }
31 $skinDir->close();
32 unset($matches);
33
34 require_once( 'RecentChange.php' );
35
36 global $wgLinkHolders;
37 $wgLinkHolders = array(
38 'namespaces' => array(),
39 'dbkeys' => array(),
40 'queries' => array(),
41 'texts' => array(),
42 'titles' => array()
43 );
44 global $wgInterwikiLinkHolders;
45 $wgInterwikiLinkHolders = array();
46
47 /**
48 * @todo document
49 * @package MediaWiki
50 */
51 class RCCacheEntry extends RecentChange
52 {
53 var $secureName, $link;
54 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
55 var $userlink, $timestamp, $watched;
56
57 function newFromParent( $rc )
58 {
59 $rc2 = new RCCacheEntry;
60 $rc2->mAttribs = $rc->mAttribs;
61 $rc2->mExtra = $rc->mExtra;
62 return $rc2;
63 }
64 } ;
65
66
67 /**
68 * The main skin class that provide methods and properties for all other skins
69 * including PHPTal skins.
70 * This base class is also the "Standard" skin.
71 * @package MediaWiki
72 */
73 class Skin {
74 /**#@+
75 * @access private
76 */
77 var $lastdate, $lastline;
78 var $linktrail ; # linktrail regexp
79 var $rc_cache ; # Cache for Enhanced Recent Changes
80 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
81 var $rcMoveIndex;
82 var $postParseLinkColour = false;
83 /**#@-*/
84
85 function Skin() {
86 $this->linktrail = wfMsgForContent('linktrail');
87 }
88
89 function getSkinNames() {
90 global $wgValidSkinNames;
91 return $wgValidSkinNames;
92 }
93
94 function getStylesheet() {
95 return 'common/wikistandard.css';
96 }
97
98 function getSkinName() {
99 return 'standard';
100 }
101
102 /**
103 * Get/set accessor for delayed link colouring
104 */
105 function postParseLinkColour( $setting = NULL ) {
106 return wfSetVar( $this->postParseLinkColour, $setting );
107 }
108
109 function qbSetting() {
110 global $wgOut, $wgUser;
111
112 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
113 $q = $wgUser->getOption( 'quickbar' );
114 if ( '' == $q ) { $q = 0; }
115 return $q;
116 }
117
118 function initPage( &$out ) {
119 $fname = 'Skin::initPage';
120 wfProfileIn( $fname );
121
122 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
123
124 $this->addMetadataLinks($out);
125
126 wfProfileOut( $fname );
127 }
128
129 function addMetadataLinks( &$out ) {
130 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
131 global $wgRightsPage, $wgRightsUrl;
132
133 if( $out->isArticleRelated() ) {
134 # note: buggy CC software only reads first "meta" link
135 if( $wgEnableCreativeCommonsRdf ) {
136 $out->addMetadataLink( array(
137 'title' => 'Creative Commons',
138 'type' => 'application/rdf+xml',
139 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
140 }
141 if( $wgEnableDublinCoreRdf ) {
142 $out->addMetadataLink( array(
143 'title' => 'Dublin Core',
144 'type' => 'application/rdf+xml',
145 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
146 }
147 }
148 $copyright = '';
149 if( $wgRightsPage ) {
150 $copy = Title::newFromText( $wgRightsPage );
151 if( $copy ) {
152 $copyright = $copy->getLocalURL();
153 }
154 }
155 if( !$copyright && $wgRightsUrl ) {
156 $copyright = $wgRightsUrl;
157 }
158 if( $copyright ) {
159 $out->addLink( array(
160 'rel' => 'copyright',
161 'href' => $copyright ) );
162 }
163 }
164
165 function outputPage( &$out ) {
166 global $wgDebugComments;
167
168 wfProfileIn( 'Skin::outputPage' );
169 $this->initPage( $out );
170 $out->out( $out->headElement() );
171
172 $out->out( "\n<body" );
173 $ops = $this->getBodyOptions();
174 foreach ( $ops as $name => $val ) {
175 $out->out( " $name='$val'" );
176 }
177 $out->out( ">\n" );
178 if ( $wgDebugComments ) {
179 $out->out( "<!-- Wiki debugging output:\n" .
180 $out->mDebugtext . "-->\n" );
181 }
182 $out->out( $this->beforeContent() );
183
184 $out->out( $out->mBodytext . "\n" );
185
186 $out->out( $this->afterContent() );
187
188 wfProfileClose();
189 $out->out( $out->reportTime() );
190
191 $out->out( "\n</body></html>" );
192 }
193
194 function getHeadScripts() {
195 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
196 $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
197 if( $wgAllowUserJs && $wgUser->getID() != 0 ) { # logged in
198 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
199 $userjs = htmlspecialchars($this->makeUrl($userpage.'/'.$this->getSkinName().'.js', 'action=raw&ctype=text/javascript'));
200 $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
201 }
202 return $r;
203 }
204
205 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
206 function getUserStylesheet() {
207 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
208 $sheet = $this->getStylesheet();
209 $action = $wgRequest->getText('action');
210 $s = "@import \"$wgStylePath/$sheet\";\n";
211 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
212 if( $wgAllowUserCss && $wgUser->getID() != 0 ) { # logged in
213 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
214 $s .= $wgRequest->getText('wpTextbox1');
215 } else {
216 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
217 $s.= '@import "'.$this->makeUrl($userpage.'/'.$this->getSkinName().'.css', 'action=raw&ctype=text/css').'";'."\n";
218 }
219 }
220 $s .= $this->doGetUserStyles();
221 return $s."\n";
222 }
223
224 /**
225 * placeholder, returns generated js in monobook
226 */
227 function getUserJs() { return; }
228
229 /**
230 * Return html code that include User stylesheets
231 */
232 function getUserStyles() {
233 global $wgOut, $wgStylePath, $wgLang;
234 $s = "<style type='text/css'>\n";
235 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
236 $s .= $this->getUserStylesheet();
237 $s .= "/*]]>*/ /* */\n";
238 $s .= "</style>\n";
239 return $s;
240 }
241
242 /**
243 * Some styles that are set by user through the user settings interface.
244 */
245 function doGetUserStyles() {
246 global $wgUser, $wgContLang;
247
248 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
249 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
250
251 if ( 1 == $wgUser->getOption( 'underline' ) ) {
252 # Don't override browser settings
253 } else {
254 # CHECK MERGE @@@
255 # Force no underline
256 $s .= "a { text-decoration: none; }\n";
257 }
258 if ( 1 == $wgUser->getOption( 'highlightbroken' ) ) {
259 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
260 }
261 if ( 1 == $wgUser->getOption( 'justify' ) ) {
262 $s .= "#article { text-align: justify; }\n";
263 }
264 return $s;
265 }
266
267 function getBodyOptions() {
268 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
269
270 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
271
272 if ( 0 != $wgTitle->getNamespace() ) {
273 $a = array( 'bgcolor' => '#ffffec' );
274 }
275 else $a = array( 'bgcolor' => '#FFFFFF' );
276 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
277 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
278 $t = wfMsg( 'editthispage' );
279 $oid = $red = '';
280 if ( !empty($redirect) && $redirect == 'no' ) {
281 $red = "&redirect={$redirect}";
282 }
283 if ( !empty($oldid) && ! isset( $diff ) ) {
284 $oid = "&oldid=" . IntVal( $oldid );
285 }
286 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
287 $s = 'document.location = "' .$s .'";';
288 $a += array ('ondblclick' => $s);
289
290 }
291 $a['onload'] = $wgOut->getOnloadHandler();
292 return $a;
293 }
294
295 function getExternalLinkAttributes( $link, $text, $class='' ) {
296 global $wgUser, $wgOut, $wgContLang;
297
298 $same = ($link == $text);
299 $link = urldecode( $link );
300 $link = $wgContLang->checkTitleEncoding( $link );
301 $link = str_replace( '_', ' ', $link );
302 $link = htmlspecialchars( $link );
303
304 $r = ($class != '') ? " class='$class'" : " class='external'";
305
306 if ( !$same && $wgUser->getOption( 'hover' ) ) {
307 $r .= " title=\"{$link}\"";
308 }
309 return $r;
310 }
311
312 function getInternalLinkAttributes( $link, $text, $broken = false ) {
313 global $wgUser, $wgOut;
314
315 $link = urldecode( $link );
316 $link = str_replace( '_', ' ', $link );
317 $link = htmlspecialchars( $link );
318
319 if ( $broken == 'stub' ) {
320 $r = ' class="stub"';
321 } else if ( $broken == 'yes' ) {
322 $r = ' class="new"';
323 } else {
324 $r = '';
325 }
326
327 if ( 1 == $wgUser->getOption( 'hover' ) ) {
328 $r .= " title=\"{$link}\"";
329 }
330 return $r;
331 }
332
333 /**
334 * @param bool $broken
335 */
336 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
337 global $wgUser, $wgOut;
338
339 if ( $broken == 'stub' ) {
340 $r = ' class="stub"';
341 } else if ( $broken == 'yes' ) {
342 $r = ' class="new"';
343 } else {
344 $r = '';
345 }
346
347 if ( 1 == $wgUser->getOption( 'hover' ) ) {
348 $r .= ' title="' . $nt->getEscapedText() . '"';
349 }
350 return $r;
351 }
352
353 /**
354 * URL to the logo
355 */
356 function getLogo() {
357 global $wgLogo;
358 return $wgLogo;
359 }
360
361 /**
362 * This will be called immediately after the <body> tag. Split into
363 * two functions to make it easier to subclass.
364 */
365 function beforeContent() {
366 global $wgUser, $wgOut;
367
368 return $this->doBeforeContent();
369 }
370
371 function doBeforeContent() {
372 global $wgUser, $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
373 $fname = 'Skin::doBeforeContent';
374 wfProfileIn( $fname );
375
376 $s = '';
377 $qb = $this->qbSetting();
378
379 if( $langlinks = $this->otherLanguages() ) {
380 $rows = 2;
381 $borderhack = '';
382 } else {
383 $rows = 1;
384 $langlinks = false;
385 $borderhack = 'class="top"';
386 }
387
388 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
389 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
390
391 $shove = ($qb != 0);
392 $left = ($qb == 1 || $qb == 3);
393 if($wgContLang->isRTL()) $left = !$left;
394
395 if ( !$shove ) {
396 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
397 $this->logoText() . '</td>';
398 } elseif( $left ) {
399 $s .= $this->getQuickbarCompensator( $rows );
400 }
401 $l = $wgContLang->isRTL() ? 'right' : 'left';
402 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
403
404 $s .= $this->topLinks() ;
405 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
406
407 $r = $wgContLang->isRTL() ? "left" : "right";
408 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
409 $s .= $this->nameAndLogin();
410 $s .= "\n<br />" . $this->searchForm() . "</td>";
411
412 if ( $langlinks ) {
413 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
414 }
415
416 if ( $shove && !$left ) { # Right
417 $s .= $this->getQuickbarCompensator( $rows );
418 }
419 $s .= "</tr>\n</table>\n</div>\n";
420 $s .= "\n<div id='article'>\n";
421
422 if( $wgSiteNotice ) {
423 $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
424 }
425 $s .= $this->pageTitle();
426 $s .= $this->pageSubtitle() ;
427 $s .= $this->getCategories();
428 wfProfileOut( $fname );
429 return $s;
430 }
431
432
433 function getCategoryLinks () {
434 global $wgOut, $wgTitle, $wgUser, $wgParser;
435 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
436
437 if( !$wgUseCategoryMagic ) return '' ;
438 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
439
440 # Taken out so that they will be displayed in previews -- TS
441 #if( !$wgOut->isArticle() ) return '';
442
443 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
444 $s = $this->makeKnownLink( 'Special:Categories',
445 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
446 . ': ' . $t;
447
448 # optional 'dmoz-like' category browser. Will be shown under the list
449 # of categories an article belong to
450 if($wgUseCategoryBrowser) {
451 $s .= '<br/><hr/>';
452
453 # get a big array of the parents tree
454 $parenttree = $wgTitle->getParentCategoryTree();
455
456 # Render the array as a serie of links
457 function walkThrough ($tree) {
458 global $wgUser;
459 $sk = $wgUser->getSkin();
460 $return = '';
461 foreach($tree as $element => $parent) {
462 if(empty($parent)) {
463 # element start a new list
464 $return .= '<br />';
465 } else {
466 # grab the others elements
467 $return .= walkThrough($parent);
468 }
469 # add our current element to the list
470 $eltitle = Title::NewFromText($element);
471 # FIXME : should be makeLink() [AV]
472 $return .= $sk->makeLink($element, $eltitle->getText()).' &gt; ';
473 }
474 return $return;
475 }
476
477 $s .= walkThrough($parenttree);
478 }
479
480 return $s;
481 }
482
483 function getCategories() {
484 $catlinks=$this->getCategoryLinks();
485 if(!empty($catlinks)) {
486 return "<p class='catlinks'>{$catlinks}</p>";
487 }
488 }
489
490 function getQuickbarCompensator( $rows = 1 ) {
491 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
492 }
493
494 # This gets called immediately before the </body> tag.
495 #
496 function afterContent() {
497 global $wgUser, $wgOut, $wgServer;
498 global $wgTitle, $wgLang;
499
500 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
501 return $printfooter . $this->doAfterContent();
502 }
503
504 function printSource() {
505 global $wgTitle;
506 $url = htmlspecialchars( $wgTitle->getFullURL() );
507 return wfMsg( "retrievedfrom", "<a href=\"$url\">$url</a>" );
508 }
509
510 function printFooter() {
511 return "<p>" . $this->printSource() .
512 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
513 }
514
515 function doAfterContent() {
516 # overloaded by derived classes
517 }
518
519 function pageTitleLinks() {
520 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
521
522 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
523 $action = $wgRequest->getText( 'action' );
524
525 $s = $this->printableLink();
526 $disclaimer = $this->disclaimerLink(); # may be empty
527 if( $disclaimer ) {
528 $s .= ' | ' . $disclaimer;
529 }
530
531 if ( $wgOut->isArticleRelated() ) {
532 if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
533 $name = $wgTitle->getDBkey();
534 $link = htmlspecialchars( Image::wfImageUrl( $name ) );
535 $style = $this->getInternalLinkAttributes( $link, $name );
536 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
537 }
538 # This will show the "Approve" link if $wgUseApproval=true;
539 if ( isset ( $wgUseApproval ) && $wgUseApproval )
540 {
541 $t = $wgTitle->getDBkey();
542 $name = 'Approve this article' ;
543 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
544 #htmlspecialchars( wfImageUrl( $name ) );
545 $style = $this->getExternalLinkAttributes( $link, $name );
546 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
547 }
548 }
549 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
550 $s .= ' | ' . $this->makeKnownLink( $wgTitle->getPrefixedText(),
551 wfMsg( 'currentrev' ) );
552 }
553
554 if ( $wgUser->getNewtalk() ) {
555 # do not show "You have new messages" text when we are viewing our
556 # own talk page
557
558 if(!(strcmp($wgTitle->getText(),$wgUser->getName()) == 0 &&
559 $wgTitle->getNamespace()==Namespace::getTalk(Namespace::getUser()))) {
560 $n =$wgUser->getName();
561 $tl = $this->makeKnownLink( $wgContLang->getNsText(
562 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
563 wfMsg('newmessageslink') );
564 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
565 # disable caching
566 $wgOut->setSquidMaxage(0);
567 $wgOut->enableClientCache(false);
568 }
569 }
570
571 $undelete = $this->getUndeleteLink();
572 if( !empty( $undelete ) ) {
573 $s .= ' | '.$undelete;
574 }
575 return $s;
576 }
577
578 function getUndeleteLink() {
579 global $wgUser, $wgTitle, $wgContLang, $action;
580 if( $wgUser->isAllowed('rollback') &&
581 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
582 ($n = $wgTitle->isDeleted() ) ) {
583 return wfMsg( 'thisisdeleted',
584 $this->makeKnownLink(
585 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
586 wfMsg( 'restorelink', $n ) ) );
587 }
588 return '';
589 }
590
591 function printableLink() {
592 global $wgOut, $wgFeedClasses, $wgRequest;
593
594 $baseurl = $_SERVER['REQUEST_URI'];
595 if( strpos( '?', $baseurl ) == false ) {
596 $baseurl .= '?';
597 } else {
598 $baseurl .= '&';
599 }
600 $baseurl = htmlspecialchars( $baseurl );
601 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
602
603 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
604 if( $wgOut->isSyndicated() ) {
605 foreach( $wgFeedClasses as $format => $class ) {
606 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
607 $s .= " | <a href=\"$feedurl\">{$format}</a>";
608 }
609 }
610 return $s;
611 }
612
613 function pageTitle() {
614 global $wgOut, $wgTitle, $wgUser;
615
616 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
617 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
618 return $s;
619 }
620
621 function pageSubtitle() {
622 global $wgOut;
623
624 $sub = $wgOut->getSubtitle();
625 if ( '' == $sub ) {
626 global $wgExtraSubtitle;
627 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
628 }
629 $subpages = $this->subPageSubtitle();
630 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
631 $s = "<p class='subtitle'>{$sub}</p>\n";
632 return $s;
633 }
634
635 function subPageSubtitle() {
636 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
637 $subpages = '';
638 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
639 $ptext=$wgTitle->getPrefixedText();
640 if(preg_match('/\//',$ptext)) {
641 $links = explode('/',$ptext);
642 $c = 0;
643 $growinglink = '';
644 foreach($links as $link) {
645 $c++;
646 if ($c<count($links)) {
647 $growinglink .= $link;
648 $getlink = $this->makeLink( $growinglink, $link );
649 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
650 if ($c>1) {
651 $subpages .= ' | ';
652 } else {
653 $subpages .= '&lt; ';
654 }
655 $subpages .= $getlink;
656 $growinglink .= '/';
657 }
658 }
659 }
660 }
661 return $subpages;
662 }
663
664 function nameAndLogin() {
665 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
666
667 $li = $wgContLang->specialPage( 'Userlogin' );
668 $lo = $wgContLang->specialPage( 'Userlogout' );
669
670 $s = '';
671 if ( 0 == $wgUser->getID() ) {
672 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
673 $n = $wgIP;
674
675 $tl = $this->makeKnownLink( $wgContLang->getNsText(
676 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
677 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
678
679 $s .= $n . ' ('.$tl.')';
680 } else {
681 $s .= wfMsg('notloggedin');
682 }
683
684 $rt = $wgTitle->getPrefixedURL();
685 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
686 $q = '';
687 } else { $q = "returnto={$rt}"; }
688
689 $s .= "\n<br />" . $this->makeKnownLink( $li,
690 wfMsg( 'login' ), $q );
691 } else {
692 $n = $wgUser->getName();
693 $rt = $wgTitle->getPrefixedURL();
694 $tl = $this->makeKnownLink( $wgContLang->getNsText(
695 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
696 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
697
698 $tl = " ({$tl})";
699
700 $s .= $this->makeKnownLink( $wgContLang->getNsText(
701 Namespace::getUser() ) . ":{$n}", $n ) . "{$tl}<br />" .
702 $this->makeKnownLink( $lo, wfMsg( 'logout' ),
703 "returnto={$rt}" ) . ' | ' .
704 $this->specialLink( 'preferences' );
705 }
706 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
707 wfMsg( 'help' ) );
708
709 return $s;
710 }
711
712 function getSearchLink() {
713 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
714 return $searchPage->getLocalURL();
715 }
716
717 function escapeSearchLink() {
718 return htmlspecialchars( $this->getSearchLink() );
719 }
720
721 function searchForm() {
722 global $wgRequest;
723 $search = $wgRequest->getText( 'search' );
724
725 $s = '<form name="search" class="inline" method="post" action="'
726 . $this->escapeSearchLink() . "\">\n"
727 . '<input type="text" name="search" size="19" value="'
728 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
729 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
730 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
731
732 return $s;
733 }
734
735 function topLinks() {
736 global $wgOut;
737 $sep = " |\n";
738
739 $s = $this->mainPageLink() . $sep
740 . $this->specialLink( 'recentchanges' );
741
742 if ( $wgOut->isArticleRelated() ) {
743 $s .= $sep . $this->editThisPage()
744 . $sep . $this->historyLink();
745 }
746 # Many people don't like this dropdown box
747 #$s .= $sep . $this->specialPagesList();
748
749 return $s;
750 }
751
752 function bottomLinks() {
753 global $wgOut, $wgUser, $wgTitle;
754 $sep = " |\n";
755
756 $s = '';
757 if ( $wgOut->isArticleRelated() ) {
758 $s .= '<strong>' . $this->editThisPage() . '</strong>';
759 if ( 0 != $wgUser->getID() ) {
760 $s .= $sep . $this->watchThisPage();
761 }
762 $s .= $sep . $this->talkLink()
763 . $sep . $this->historyLink()
764 . $sep . $this->whatLinksHere()
765 . $sep . $this->watchPageLinksLink();
766
767 if ( $wgTitle->getNamespace() == Namespace::getUser()
768 || $wgTitle->getNamespace() == Namespace::getTalk(Namespace::getUser()) )
769
770 {
771 $id=User::idFromName($wgTitle->getText());
772 $ip=User::isIP($wgTitle->getText());
773
774 if($id || $ip) { # both anons and non-anons have contri list
775 $s .= $sep . $this->userContribsLink();
776 }
777 if( $this->showEmailUser( $id ) ) {
778 $s .= $sep . $this->emailUserLink();
779 }
780 }
781 if ( $wgTitle->getArticleId() ) {
782 $s .= "\n<br />";
783 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
784 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
785 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
786 }
787 $s .= "<br />\n" . $this->otherLanguages();
788 }
789 return $s;
790 }
791
792 function pageStats() {
793 global $wgOut, $wgLang, $wgArticle, $wgRequest;
794 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax;
795
796 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
797 if ( ! $wgOut->isArticle() ) { return ''; }
798 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
799 if ( 0 == $wgArticle->getID() ) { return ''; }
800
801 $s = '';
802 if ( !$wgDisableCounters ) {
803 $count = $wgLang->formatNum( $wgArticle->getCount() );
804 if ( $count ) {
805 $s = wfMsg( 'viewcount', $count );
806 }
807 }
808
809 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
810 require_once("Credits.php");
811 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
812 } else {
813 $s .= $this->lastModified();
814 }
815
816 return $s . ' ' . $this->getCopyright();
817 }
818
819 function getCopyright() {
820 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
821
822
823 $oldid = $wgRequest->getVal( 'oldid' );
824 $diff = $wgRequest->getVal( 'diff' );
825
826 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
827 $msg = 'history_copyright';
828 } else {
829 $msg = 'copyright';
830 }
831
832 $out = '';
833 if( $wgRightsPage ) {
834 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
835 } elseif( $wgRightsUrl ) {
836 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
837 } else {
838 # Give up now
839 return $out;
840 }
841 $out .= wfMsgForContent( $msg, $link );
842 return $out;
843 }
844
845 function getCopyrightIcon() {
846 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon;
847 $out = '';
848 if( $wgRightsIcon ) {
849 $icon = htmlspecialchars( $wgRightsIcon );
850 if( $wgRightsUrl ) {
851 $url = htmlspecialchars( $wgRightsUrl );
852 $out .= '<a href="'.$url.'">';
853 }
854 $text = htmlspecialchars( $wgRightsText );
855 $out .= "<img src=\"$icon\" alt='$text' />";
856 if( $wgRightsUrl ) {
857 $out .= '</a>';
858 }
859 }
860 return $out;
861 }
862
863 function getPoweredBy() {
864 global $wgStylePath;
865 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
866 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
867 return $img;
868 }
869
870 function lastModified() {
871 global $wgLang, $wgArticle;
872
873 $timestamp = $wgArticle->getTimestamp();
874 if ( $timestamp ) {
875 $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
876 $s = ' ' . wfMsg( 'lastmodified', $d );
877 } else {
878 $s = '';
879 }
880 return $s;
881 }
882
883 function logoText( $align = '' ) {
884 if ( '' != $align ) { $a = " align='{$align}'"; }
885 else { $a = ''; }
886
887 $mp = wfMsg( 'mainpage' );
888 $titleObj = Title::newFromText( $mp );
889 if ( is_object( $titleObj ) ) {
890 $url = $titleObj->escapeLocalURL();
891 } else {
892 $url = '';
893 }
894
895 $logourl = $this->getLogo();
896 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
897 return $s;
898 }
899
900 /**
901 * show a drop-down box of special pages
902 * @TODO crash bug913. Need to be rewrote completly.
903 */
904 function specialPagesList() {
905 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
906 require_once('SpecialPage.php');
907 $a = array();
908 $pages = SpecialPage::getPages();
909
910 foreach ( $pages[''] as $name => $page ) {
911 $a[$name] = $page->getDescription();
912 }
913 if ( $wgUser->isSysop() )
914 {
915 foreach ( $pages['sysop'] as $name => $page ) {
916 $a[$name] = $page->getDescription();
917 }
918 }
919 if ( $wgUser->isDeveloper() )
920 {
921 foreach ( $pages['developer'] as $name => $page ) {
922 $a[$name] = $page->getDescription() ;
923 }
924 }
925 $go = wfMsg( 'go' );
926 $sp = wfMsg( 'specialpages' );
927 $spp = $wgContLang->specialPage( 'Specialpages' );
928
929 $s = '<form id="specialpages" method="get" class="inline" ' .
930 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
931 $s .= "<select name=\"wpDropdown\">\n";
932 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
933
934 foreach ( $a as $name => $desc ) {
935 $p = $wgContLang->specialPage( $name );
936 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
937 }
938 $s .= "</select>\n";
939 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
940 $s .= "</form>\n";
941 return $s;
942 }
943
944 function mainPageLink() {
945 $mp = wfMsgForContent( 'mainpage' );
946 $mptxt = wfMsg( 'mainpage');
947 $s = $this->makeKnownLink( $mp, $mptxt );
948 return $s;
949 }
950
951 function copyrightLink() {
952 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
953 wfMsg( 'copyrightpagename' ) );
954 return $s;
955 }
956
957 function aboutLink() {
958 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
959 wfMsg( 'aboutsite' ) );
960 return $s;
961 }
962
963
964 function disclaimerLink() {
965 $disclaimers = wfMsg( 'disclaimers' );
966 if ($disclaimers == '-') {
967 return "";
968 } else {
969 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
970 $disclaimers );
971 }
972 }
973
974 function editThisPage() {
975 global $wgOut, $wgTitle, $wgRequest;
976
977 $oldid = $wgRequest->getVal( 'oldid' );
978 $diff = $wgRequest->getVal( 'diff' );
979 $redirect = $wgRequest->getVal( 'redirect' );
980
981 if ( ! $wgOut->isArticleRelated() ) {
982 $s = wfMsg( 'protectedpage' );
983 } else {
984 $n = $wgTitle->getPrefixedText();
985 if ( $wgTitle->userCanEdit() ) {
986 $t = wfMsg( 'editthispage' );
987 } else {
988 #$t = wfMsg( "protectedpage" );
989 $t = wfMsg( 'viewsource' );
990 }
991 $oid = $red = '';
992
993 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
994 if ( $oldid && ! isset( $diff ) ) {
995 $oid = '&oldid='.$oldid;
996 }
997 $s = $this->makeKnownLink( $n, $t, "action=edit{$oid}{$red}" );
998 }
999 return $s;
1000 }
1001
1002 function deleteThisPage() {
1003 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1004
1005 $diff = $wgRequest->getVal( 'diff' );
1006 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1007 $n = $wgTitle->getPrefixedText();
1008 $t = wfMsg( 'deletethispage' );
1009
1010 $s = $this->makeKnownLink( $n, $t, 'action=delete' );
1011 } else {
1012 $s = '';
1013 }
1014 return $s;
1015 }
1016
1017 function protectThisPage() {
1018 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1019
1020 $diff = $wgRequest->getVal( 'diff' );
1021 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1022 $n = $wgTitle->getPrefixedText();
1023
1024 if ( $wgTitle->isProtected() ) {
1025 $t = wfMsg( 'unprotectthispage' );
1026 $q = 'action=unprotect';
1027 } else {
1028 $t = wfMsg( 'protectthispage' );
1029 $q = 'action=protect';
1030 }
1031 $s = $this->makeKnownLink( $n, $t, $q );
1032 } else {
1033 $s = '';
1034 }
1035 return $s;
1036 }
1037
1038 function watchThisPage() {
1039 global $wgUser, $wgOut, $wgTitle;
1040
1041 if ( $wgOut->isArticleRelated() ) {
1042 $n = $wgTitle->getPrefixedText();
1043
1044 if ( $wgTitle->userIsWatching() ) {
1045 $t = wfMsg( 'unwatchthispage' );
1046 $q = 'action=unwatch';
1047 } else {
1048 $t = wfMsg( 'watchthispage' );
1049 $q = 'action=watch';
1050 }
1051 $s = $this->makeKnownLink( $n, $t, $q );
1052 } else {
1053 $s = wfMsg( 'notanarticle' );
1054 }
1055 return $s;
1056 }
1057
1058 function moveThisPage() {
1059 global $wgTitle, $wgContLang;
1060
1061 if ( $wgTitle->userCanMove() ) {
1062 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
1063 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1064 } // no message if page is protected - would be redundant
1065 return $s;
1066 }
1067
1068 function historyLink() {
1069 global $wgTitle;
1070
1071 $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
1072 wfMsg( 'history' ), 'action=history' );
1073 return $s;
1074 }
1075
1076 function whatLinksHere() {
1077 global $wgTitle, $wgContLang;
1078
1079 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ),
1080 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1081 return $s;
1082 }
1083
1084 function userContribsLink() {
1085 global $wgTitle, $wgContLang;
1086
1087 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
1088 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1089 return $s;
1090 }
1091
1092 function showEmailUser( $id ) {
1093 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1094 return $wgEnableEmail &&
1095 $wgEnableUserEmail &&
1096 0 != $wgUser->getID() && # show only to signed in users
1097 0 != $id; # can only email non-anons
1098 }
1099
1100 function emailUserLink() {
1101 global $wgTitle, $wgContLang;
1102
1103 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Emailuser' ),
1104 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1105 return $s;
1106 }
1107
1108 function watchPageLinksLink() {
1109 global $wgOut, $wgTitle, $wgContLang;
1110
1111 if ( ! $wgOut->isArticleRelated() ) {
1112 $s = '(' . wfMsg( 'notanarticle' ) . ')';
1113 } else {
1114 $s = $this->makeKnownLink( $wgContLang->specialPage(
1115 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1116 'target=' . $wgTitle->getPrefixedURL() );
1117 }
1118 return $s;
1119 }
1120
1121 function otherLanguages() {
1122 global $wgOut, $wgContLang, $wgTitle, $wgUseNewInterlanguage;
1123
1124 $a = $wgOut->getLanguageLinks();
1125 if ( 0 == count( $a ) ) {
1126 if ( !$wgUseNewInterlanguage ) return '';
1127 $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ;
1128 if ( $ns != 0 AND $ns != 1 ) return '' ;
1129 $pn = 'Intl' ;
1130 $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ;
1131 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1132 wfMsg( 'intl' ) , $x );
1133 }
1134
1135 if ( !$wgUseNewInterlanguage ) {
1136 $s = wfMsg( 'otherlanguages' ) . ': ';
1137 } else {
1138 global $wgContLanguageCode ;
1139 $x = 'mode=zoom&xt='.$wgTitle->getDBkey() ;
1140 $x .= '&xl='.$wgContLanguageCode ;
1141 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Intl' ),
1142 wfMsg( 'otherlanguages' ) , $x ) . ': ' ;
1143 }
1144
1145 $s = wfMsg( 'otherlanguages' ) . ': ';
1146 $first = true;
1147 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1148 foreach( $a as $l ) {
1149 if ( ! $first ) { $s .= ' | '; }
1150 $first = false;
1151
1152 $nt = Title::newFromText( $l );
1153 $url = $nt->getFullURL();
1154 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1155
1156 if ( '' == $text ) { $text = $l; }
1157 $style = $this->getExternalLinkAttributes( $l, $text );
1158 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1159 }
1160 if($wgContLang->isRTL()) $s .= '</span>';
1161 return $s;
1162 }
1163
1164 function bugReportsLink() {
1165 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1166 wfMsg( 'bugreports' ) );
1167 return $s;
1168 }
1169
1170 function dateLink() {
1171 global $wgLinkCache;
1172 $t1 = Title::newFromText( gmdate( 'F j' ) );
1173 $t2 = Title::newFromText( gmdate( 'Y' ) );
1174
1175 $wgLinkCache->suspend();
1176 $id = $t1->getArticleID();
1177 $wgLinkCache->resume();
1178
1179 if ( 0 == $id ) {
1180 $s = $this->makeBrokenLink( $t1->getText() );
1181 } else {
1182 $s = $this->makeKnownLink( $t1->getText() );
1183 }
1184 $s .= ', ';
1185
1186 $wgLinkCache->suspend();
1187 $id = $t2->getArticleID();
1188 $wgLinkCache->resume();
1189
1190 if ( 0 == $id ) {
1191 $s .= $this->makeBrokenLink( $t2->getText() );
1192 } else {
1193 $s .= $this->makeKnownLink( $t2->getText() );
1194 }
1195 return $s;
1196 }
1197
1198 function talkLink() {
1199 global $wgContLang, $wgTitle, $wgLinkCache;
1200
1201 $tns = $wgTitle->getNamespace();
1202 if ( -1 == $tns ) { return ''; }
1203
1204 $pn = $wgTitle->getText();
1205 $tp = wfMsg( 'talkpage' );
1206 if ( Namespace::isTalk( $tns ) ) {
1207 $lns = Namespace::getSubject( $tns );
1208 switch($tns) {
1209 case 1:
1210 $text = wfMsg('articlepage');
1211 break;
1212 case 3:
1213 $text = wfMsg('userpage');
1214 break;
1215 case 5:
1216 $text = wfMsg('wikipediapage');
1217 break;
1218 case 7:
1219 $text = wfMsg('imagepage');
1220 break;
1221 default:
1222 $text= wfMsg('articlepage');
1223 }
1224 } else {
1225
1226 $lns = Namespace::getTalk( $tns );
1227 $text=$tp;
1228 }
1229 $n = $wgContLang->getNsText( $lns );
1230 if ( '' == $n ) { $link = $pn; }
1231 else { $link = $n.':'.$pn; }
1232
1233 $wgLinkCache->suspend();
1234 $s = $this->makeLink( $link, $text );
1235 $wgLinkCache->resume();
1236
1237 return $s;
1238 }
1239
1240 function commentLink() {
1241 global $wgContLang, $wgTitle, $wgLinkCache;
1242
1243 $tns = $wgTitle->getNamespace();
1244 if ( -1 == $tns ) { return ''; }
1245
1246 $lns = ( Namespace::isTalk( $tns ) ) ? $tns : Namespace::getTalk( $tns );
1247
1248 # assert Namespace::isTalk( $lns )
1249
1250 $n = $wgContLang->getNsText( $lns );
1251 $pn = $wgTitle->getText();
1252
1253 $link = $n.':'.$pn;
1254
1255 $wgLinkCache->suspend();
1256 $s = $this->makeKnownLink($link, wfMsg('postcomment'), 'action=edit&section=new');
1257 $wgLinkCache->resume();
1258
1259 return $s;
1260 }
1261
1262 /**
1263 * After all the page content is transformed into HTML, it makes
1264 * a final pass through here for things like table backgrounds.
1265 * @todo probably deprecated [AV]
1266 */
1267 function transformContent( $text ) {
1268 return $text;
1269 }
1270
1271 /**
1272 * Note: This function MUST call getArticleID() on the link,
1273 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
1274 */
1275 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1276 wfProfileIn( 'Skin::makeLink' );
1277 $nt = Title::newFromText( $title );
1278 if ($nt) {
1279 $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1280 } else {
1281 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
1282 $result = $text == "" ? $title : $text;
1283 }
1284
1285 wfProfileOut( 'Skin::makeLink' );
1286 return $result;
1287 }
1288
1289 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1290 $nt = Title::newFromText( $title );
1291 if ($nt) {
1292 return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
1293 } else {
1294 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
1295 return $text == '' ? $title : $text;
1296 }
1297 }
1298
1299 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1300 $nt = Title::newFromText( $title );
1301 if ($nt) {
1302 return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1303 } else {
1304 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
1305 return $text == '' ? $title : $text;
1306 }
1307 }
1308
1309 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1310 $nt = Title::newFromText( $title );
1311 if ($nt) {
1312 return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1313 } else {
1314 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
1315 return $text == '' ? $title : $text;
1316 }
1317 }
1318
1319 /**
1320 * Pass a title object, not a title string
1321 */
1322 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1323 global $wgOut, $wgUser, $wgLinkHolders;
1324 $fname = 'Skin::makeLinkObj';
1325
1326 # Fail gracefully
1327 if ( ! isset($nt) ) {
1328 # wfDebugDieBacktrace();
1329 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1330 }
1331
1332 if ( $nt->isExternal() ) {
1333 $u = $nt->getFullURL();
1334 $link = $nt->getPrefixedURL();
1335 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
1336 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
1337
1338 $inside = '';
1339 if ( '' != $trail ) {
1340 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
1341 $inside = $m[1];
1342 $trail = $m[2];
1343 }
1344 }
1345 # Assume $this->postParseLinkColour(). This prevents
1346 # interwiki links from being parsed as external links.
1347 global $wgInterwikiLinkHolders;
1348 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
1349 $nr = array_push($wgInterwikiLinkHolders, $t);
1350 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
1351 } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) {
1352 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1353 } elseif ( ( -1 == $nt->getNamespace() ) ||
1354 ( NS_IMAGE == $nt->getNamespace() ) ) {
1355 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1356 } else {
1357 if ( $this->postParseLinkColour() ) {
1358 $inside = '';
1359 if ( '' != $trail ) {
1360 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1361 $inside = $m[1];
1362 $trail = $m[2];
1363 }
1364 }
1365
1366 # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders()
1367 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
1368 $wgLinkHolders['dbkeys'][] = $nt->getDBkey();
1369 $wgLinkHolders['queries'][] = $query;
1370 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
1371 $wgLinkHolders['titles'][] = $nt;
1372
1373 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
1374 } else {
1375 # Work out link colour immediately
1376 $aid = $nt->getArticleID() ;
1377 if ( 0 == $aid ) {
1378 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
1379 } else {
1380 $threshold = $wgUser->getOption('stubthreshold') ;
1381 if ( $threshold > 0 ) {
1382 $dbr =& wfGetDB( DB_SLAVE );
1383 $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
1384 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
1385 if ( $s !== false ) {
1386 $size = $s->x;
1387 if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
1388 $size = $threshold*2 ; # Really big
1389 }
1390 $dbr->freeResult( $res );
1391 } else {
1392 $size = $threshold*2 ; # Really big
1393 }
1394 } else {
1395 $size = 1 ;
1396 }
1397 if ( $size < $threshold ) {
1398 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1399 } else {
1400 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1401 }
1402 }
1403 }
1404 }
1405 return $retVal;
1406 }
1407
1408 /**
1409 * Pass a title object, not a title string
1410 */
1411 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1412 global $wgOut, $wgTitle, $wgInputEncoding;
1413
1414 $fname = 'Skin::makeKnownLinkObj';
1415 wfProfileIn( $fname );
1416
1417 if ( !is_object( $nt ) ) {
1418 wfProfileIn( $fname );
1419 return $text;
1420 }
1421
1422 $u = $nt->escapeLocalURL( $query );
1423 if ( '' != $nt->getFragment() ) {
1424 if( $nt->getPrefixedDbkey() == '' ) {
1425 $u = '';
1426 if ( '' == $text ) {
1427 $text = htmlspecialchars( $nt->getFragment() );
1428 }
1429 }
1430 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1431 $replacearray = array(
1432 '%3A' => ':',
1433 '%' => '.'
1434 );
1435 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1436 }
1437 if ( '' == $text ) {
1438 $text = htmlspecialchars( $nt->getPrefixedText() );
1439 }
1440 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1441
1442 $inside = '';
1443 if ( '' != $trail ) {
1444 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1445 $inside = $m[1];
1446 $trail = $m[2];
1447 }
1448 }
1449 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1450 wfProfileOut( $fname );
1451 return $r;
1452 }
1453
1454 /**
1455 * Pass a title object, not a title string
1456 */
1457 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1458 global $wgOut, $wgUser;
1459
1460 # Fail gracefully
1461 if ( ! isset($nt) ) {
1462 # wfDebugDieBacktrace();
1463 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1464 }
1465
1466 $fname = 'Skin::makeBrokenLinkObj';
1467 wfProfileIn( $fname );
1468
1469 if ( '' == $query ) {
1470 $q = 'action=edit';
1471 } else {
1472 $q = 'action=edit&'.$query;
1473 }
1474 $u = $nt->escapeLocalURL( $q );
1475
1476 if ( '' == $text ) {
1477 $text = htmlspecialchars( $nt->getPrefixedText() );
1478 }
1479 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1480
1481 $inside = '';
1482 if ( '' != $trail ) {
1483 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1484 $inside = $m[1];
1485 $trail = $m[2];
1486 }
1487 }
1488 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1489 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1490 } else {
1491 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1492 }
1493
1494 wfProfileOut( $fname );
1495 return $s;
1496 }
1497
1498 /**
1499 * Pass a title object, not a title string
1500 */
1501 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1502 global $wgOut, $wgUser;
1503
1504 $link = $nt->getPrefixedURL();
1505
1506 $u = $nt->escapeLocalURL( $query );
1507
1508 if ( '' == $text ) {
1509 $text = htmlspecialchars( $nt->getPrefixedText() );
1510 }
1511 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1512
1513 $inside = '';
1514 if ( '' != $trail ) {
1515 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1516 $inside = $m[1];
1517 $trail = $m[2];
1518 }
1519 }
1520 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1521 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1522 } else {
1523 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1524 }
1525 return $s;
1526 }
1527
1528 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1529 $u = $nt->escapeLocalURL( $query );
1530 if ( '' == $text ) {
1531 $text = htmlspecialchars( $nt->getPrefixedText() );
1532 }
1533 $inside = '';
1534 if ( '' != $trail ) {
1535 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1536 $inside = $m[1];
1537 $trail = $m[2];
1538 }
1539 }
1540 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1541 }
1542
1543 /* these are used extensively in SkinPHPTal, but also some other places */
1544 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1545 $title = Title::makeTitle( NS_SPECIAL, $name );
1546 $this->checkTitle($title, $name);
1547 return $title->getLocalURL( $urlaction );
1548 }
1549 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1550 $title = Title::newFromText( $name );
1551 $title = $title->getTalkPage();
1552 $this->checkTitle($title, $name);
1553 return $title->getLocalURL( $urlaction );
1554 }
1555 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1556 $title = Title::newFromText( $name );
1557 $title= $title->getSubjectPage();
1558 $this->checkTitle($title, $name);
1559 return $title->getLocalURL( $urlaction );
1560 }
1561 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1562 $title = Title::newFromText( wfMsgForContent($name) );
1563 $this->checkTitle($title, $name);
1564 return $title->getLocalURL( $urlaction );
1565 }
1566 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1567 $title = Title::newFromText( $name );
1568 $this->checkTitle($title, $name);
1569 return $title->getLocalURL( $urlaction );
1570 }
1571
1572 # If url string starts with http, consider as external URL, else
1573 # internal
1574 /*static*/ function makeInternalOrExternalUrl( $name ) {
1575 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1576 return $name;
1577 } else {
1578 return $this->makeUrl( $name );
1579 }
1580 }
1581
1582 # this can be passed the NS number as defined in Language.php
1583 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1584 $title = Title::makeTitleSafe( $namespace, $name );
1585 $this->checkTitle($title, $name);
1586 return $title->getLocalURL( $urlaction );
1587 }
1588
1589 /* these return an array with the 'href' and boolean 'exists' */
1590 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1591 $title = Title::newFromText( $name );
1592 $this->checkTitle($title, $name);
1593 return array(
1594 'href' => $title->getLocalURL( $urlaction ),
1595 'exists' => $title->getArticleID() != 0?true:false
1596 );
1597 }
1598 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1599 $title = Title::newFromText( $name );
1600 $title = $title->getTalkPage();
1601 $this->checkTitle($title, $name);
1602 return array(
1603 'href' => $title->getLocalURL( $urlaction ),
1604 'exists' => $title->getArticleID() != 0?true:false
1605 );
1606 }
1607 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1608 $title = Title::newFromText( $name );
1609 $title= $title->getSubjectPage();
1610 $this->checkTitle($title, $name);
1611 return array(
1612 'href' => $title->getLocalURL( $urlaction ),
1613 'exists' => $title->getArticleID() != 0?true:false
1614 );
1615 }
1616 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1617 $title = Title::newFromText( wfMsgForContent($name) );
1618 $this->checkTitle($title, $name);
1619 return array(
1620 'href' => $title->getLocalURL( $urlaction ),
1621 'exists' => $title->getArticleID() != 0?true:false
1622 );
1623 }
1624
1625 # make sure we have some title to operate on
1626 /*static*/ function checkTitle ( &$title, &$name ) {
1627 if(!is_object($title)) {
1628 $title = Title::newFromText( $name );
1629 if(!is_object($title)) {
1630 $title = Title::newFromText( '--error: link target missing--' );
1631 }
1632 }
1633 }
1634
1635 function fnamePart( $url ) {
1636 $basename = strrchr( $url, '/' );
1637 if ( false === $basename ) {
1638 $basename = $url;
1639 } else {
1640 $basename = substr( $basename, 1 );
1641 }
1642 return htmlspecialchars( $basename );
1643 }
1644
1645 function makeImage( $url, $alt = '' ) {
1646 global $wgOut;
1647 if ( '' == $alt ) {
1648 $alt = $this->fnamePart( $url );
1649 }
1650 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1651 return $s;
1652 }
1653
1654 function makeImageLink( $name, $url, $alt = '' ) {
1655 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1656 return $this->makeImageLinkObj( $nt, $alt );
1657 }
1658
1659 function makeImageLinkObj( $nt, $alt = '' ) {
1660 global $wgContLang, $wgUseImageResize;
1661 $img = Image::newFromTitle( $nt );
1662 $url = $img->getViewURL();
1663
1664 $align = '';
1665 $prefix = $postfix = '';
1666
1667 # Check if the alt text is of the form "options|alt text"
1668 # Options are:
1669 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1670 # * left no resizing, just left align. label is used for alt= only
1671 # * right same, but right aligned
1672 # * none same, but not aligned
1673 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1674 # * center center the image
1675 # * framed Keep original image size, no magnify-button.
1676
1677 $part = explode( '|', $alt);
1678
1679 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1680 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1681 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1682 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1683 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1684 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1685 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1686 $alt = '';
1687
1688 $height = $framed = $thumb = false;
1689 $manual_thumb = "" ;
1690
1691 foreach( $part as $key => $val ) {
1692 $val_parts = explode ( "=" , $val , 2 ) ;
1693 $left_part = array_shift ( $val_parts ) ;
1694 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1695 $thumb=true;
1696 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1697 # use manually specified thumbnail
1698 $thumb=true;
1699 $manual_thumb = array_shift ( $val_parts ) ;
1700 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1701 # remember to set an alignment, don't render immediately
1702 $align = 'right';
1703 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1704 # remember to set an alignment, don't render immediately
1705 $align = 'left';
1706 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1707 # remember to set an alignment, don't render immediately
1708 $align = 'center';
1709 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1710 # remember to set an alignment, don't render immediately
1711 $align = 'none';
1712 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1713 # $match is the image width in pixels
1714 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1715 $width = intval( $m[1] );
1716 $height = intval( $m[2] );
1717 } else {
1718 $width = intval($match);
1719 }
1720 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1721 $framed=true;
1722 } else {
1723 $alt = $val;
1724 }
1725 }
1726 if ( 'center' == $align )
1727 {
1728 $prefix = '<div class="center">';
1729 $postfix = '</div>';
1730 $align = 'none';
1731 }
1732
1733 if ( $thumb || $framed ) {
1734
1735 # Create a thumbnail. Alignment depends on language
1736 # writing direction, # right aligned for left-to-right-
1737 # languages ("Western languages"), left-aligned
1738 # for right-to-left-languages ("Semitic languages")
1739 #
1740 # If thumbnail width has not been provided, it is set
1741 # here to 180 pixels
1742 if ( $align == '' ) {
1743 $align = $wgContLang->isRTL() ? 'left' : 'right';
1744 }
1745 if ( ! isset($width) ) {
1746 $width = 180;
1747 }
1748 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1749
1750 } elseif ( isset($width) ) {
1751
1752 # Create a resized image, without the additional thumbnail
1753 # features
1754
1755 if ( ( ! $height === false )
1756 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1757 $width = $img->getWidth() * $height / $img->getHeight();
1758 }
1759 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1760 }
1761
1762 $alt = preg_replace( '/<[^>]*>/', '', $alt );
1763 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1764 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1765
1766 $u = $nt->escapeLocalURL();
1767 if ( $url == '' ) {
1768 $s = wfMsg( 'missingimage', $img->getName() );
1769 $s .= "<br>{$alt}<br>{$url}<br>\n";
1770 } else {
1771 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1772 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
1773 }
1774 if ( '' != $align ) {
1775 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1776 }
1777 return str_replace("\n", ' ',$prefix.$s.$postfix);
1778 }
1779
1780 /**
1781 * Make HTML for a thumbnail including image, border and caption
1782 * $img is an Image object
1783 */
1784 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1785 global $wgStylePath, $wgContLang;
1786 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1787 $url = $img->getViewURL();
1788
1789 #$label = htmlspecialchars( $label );
1790 $alt = preg_replace( '/<[^>]*>/', '', $label);
1791 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1792 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1793
1794 $width = $height = 0;
1795 if ( $img->exists() )
1796 {
1797 $width = $img->getWidth();
1798 $height = $img->getHeight();
1799 }
1800 if ( 0 == $width || 0 == $height )
1801 {
1802 $width = $height = 200;
1803 }
1804 if ( $boxwidth == 0 )
1805 {
1806 $boxwidth = 200;
1807 }
1808 if ( $framed )
1809 {
1810 // Use image dimensions, don't scale
1811 $boxwidth = $width;
1812 $oboxwidth = $boxwidth + 2;
1813 $boxheight = $height;
1814 $thumbUrl = $url;
1815 } else {
1816 $h = intval( $height/($width/$boxwidth) );
1817 $oboxwidth = $boxwidth + 2;
1818 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1819 {
1820 $boxwidth *= $boxheight/$h;
1821 } else {
1822 $boxheight = $h;
1823 }
1824 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1825 }
1826
1827 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1828 {
1829 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1830 $manual_img = Image::newFromTitle( $manual_title );
1831 $thumbUrl = $manual_img->getViewURL();
1832 if ( $manual_img->exists() )
1833 {
1834 $width = $manual_img->getWidth();
1835 $height = $manual_img->getHeight();
1836 $boxwidth = $width ;
1837 $boxheight = $height ;
1838 $oboxwidth = $boxwidth + 2 ;
1839 }
1840 }
1841
1842 $u = $img->getEscapeLocalURL();
1843
1844 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1845 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1846 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1847
1848 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1849 if ( $thumbUrl == '' ) {
1850 $s .= wfMsg( 'missingimage', $img->getName() );
1851 $zoomicon = '';
1852 } else {
1853 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1854 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1855 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1856 'longdesc="'.$u.'" /></a>';
1857 if ( $framed ) {
1858 $zoomicon="";
1859 } else {
1860 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1861 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1862 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1863 'width="15" height="11" alt="'.$more.'" /></a></div>';
1864 }
1865 }
1866 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1867 return str_replace("\n", ' ', $s);
1868 }
1869
1870 function makeMediaLink( $name, $url, $alt = '' ) {
1871 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1872 return $this->makeMediaLinkObj( $nt, $alt );
1873 }
1874
1875 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1876 if ( ! isset( $nt ) )
1877 {
1878 ### HOTFIX. Instead of breaking, return empty string.
1879 $s = $alt;
1880 } else {
1881 $name = $nt->getDBKey();
1882 $img = Image::newFromTitle( $nt );
1883 $url = $img->getURL();
1884 # $nourl can be set by the parser
1885 # this is a hack to mask absolute URLs, so the parser doesn't
1886 # linkify them (it is currently not context-aware)
1887 # 2004-10-25
1888 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1889 if ( empty( $alt ) ) {
1890 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1891 }
1892 $u = htmlspecialchars( $url );
1893 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1894 }
1895 return $s;
1896 }
1897
1898 function specialLink( $name, $key = '' ) {
1899 global $wgContLang;
1900
1901 if ( '' == $key ) { $key = strtolower( $name ); }
1902 $pn = $wgContLang->ucfirst( $name );
1903 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1904 wfMsg( $key ) );
1905 }
1906
1907 function makeExternalLink( $url, $text, $escape = true ) {
1908 $style = $this->getExternalLinkAttributes( $url, $text );
1909 $url = htmlspecialchars( $url );
1910 if( $escape ) {
1911 $text = htmlspecialchars( $text );
1912 }
1913 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1914 }
1915
1916 # Called by history lists and recent changes
1917 #
1918
1919 # Returns text for the start of the tabular part of RC
1920 function beginRecentChangesList() {
1921 $this->rc_cache = array() ;
1922 $this->rcMoveIndex = 0;
1923 $this->rcCacheIndex = 0 ;
1924 $this->lastdate = '';
1925 $this->rclistOpen = false;
1926 return '';
1927 }
1928
1929 function beginImageHistoryList() {
1930 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
1931 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
1932 return $s;
1933 }
1934
1935 /**
1936 * Returns text for the end of RC
1937 * If enhanced RC is in use, returns pretty much all the text
1938 */
1939 function endRecentChangesList() {
1940 $s = $this->recentChangesBlock() ;
1941 if( $this->rclistOpen ) {
1942 $s .= "</ul>\n";
1943 }
1944 return $s;
1945 }
1946
1947 /**
1948 * Enhanced RC ungrouped line
1949 */
1950 function recentChangesBlockLine ( $rcObj ) {
1951 global $wgStylePath, $wgContLang ;
1952
1953 # Get rc_xxxx variables
1954 extract( $rcObj->mAttribs ) ;
1955 $curIdEq = 'curid='.$rc_cur_id;
1956
1957 # Spacer image
1958 $r = '' ;
1959
1960 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
1961 $r .= '<tt>' ;
1962
1963 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1964 $r .= '&nbsp;&nbsp;';
1965 } else {
1966 # M, N and !
1967 $M = wfMsg( 'minoreditletter' );
1968 $N = wfMsg( 'newpageletter' );
1969
1970 if ( $rc_type == RC_NEW ) {
1971 $r .= $N ;
1972 } else {
1973 $r .= '&nbsp;' ;
1974 }
1975 if ( $rc_minor ) {
1976 $r .= $M ;
1977 } else {
1978 $r .= '&nbsp;' ;
1979 }
1980 if ( $rcObj->unpatrolled ) {
1981 $r .= '!';
1982 } else {
1983 $r .= '&nbsp;';
1984 }
1985 }
1986
1987 # Timestamp
1988 $r .= ' '.$rcObj->timestamp.' ' ;
1989 $r .= '</tt>' ;
1990
1991 # Article link
1992 $link = $rcObj->link ;
1993 if ( $rcObj->watched ) $link = '<strong>'.$link.'</strong>' ;
1994 $r .= $link ;
1995
1996 # Diff
1997 $r .= ' (' ;
1998 $r .= $rcObj->difflink ;
1999 $r .= '; ' ;
2000
2001 # Hist
2002 $r .= $this->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2003
2004 # User/talk
2005 $r .= ') . . '.$rcObj->userlink ;
2006 $r .= $rcObj->usertalklink ;
2007
2008 # Comment
2009 if ( $rc_comment != '' && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2010 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2011 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' );
2012 }
2013
2014 $r .= "<br />\n" ;
2015 return $r ;
2016 }
2017
2018 /**
2019 * Enhanced RC group
2020 */
2021 function recentChangesBlockGroup ( $block ) {
2022 global $wgStylePath, $wgContLang ;
2023
2024 $r = '' ;
2025 $M = wfMsg( 'minoreditletter' );
2026 $N = wfMsg( 'newpageletter' );
2027
2028 # Collate list of users
2029 $isnew = false ;
2030 $unpatrolled = false;
2031 $userlinks = array () ;
2032 foreach ( $block AS $rcObj ) {
2033 $oldid = $rcObj->mAttribs['rc_last_oldid'];
2034 if ( $rcObj->mAttribs['rc_new'] ) {
2035 $isnew = true ;
2036 }
2037 $u = $rcObj->userlink ;
2038 if ( !isset ( $userlinks[$u] ) ) {
2039 $userlinks[$u] = 0 ;
2040 }
2041 if ( $rcObj->unpatrolled ) {
2042 $unpatrolled = true;
2043 }
2044 $userlinks[$u]++ ;
2045 }
2046
2047 # Sort the list and convert to text
2048 krsort ( $userlinks ) ;
2049 asort ( $userlinks ) ;
2050 $users = array () ;
2051 foreach ( $userlinks as $userlink => $count) {
2052 $text = $userlink ;
2053 if ( $count > 1 ) $text .= " ({$count}&times;)" ;
2054 array_push ( $users , $text ) ;
2055 }
2056 $users = ' <font size="-1">['.implode('; ',$users).']</font>' ;
2057
2058 # Arrow
2059 $rci = 'RCI'.$this->rcCacheIndex ;
2060 $rcl = 'RCL'.$this->rcCacheIndex ;
2061 $rcm = 'RCM'.$this->rcCacheIndex ;
2062 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
2063 $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
2064 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
2065 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" alt="-" /></a></span>' ;
2066 $r .= $tl ;
2067
2068 # Main line
2069 # M/N
2070 $r .= '<tt>' ;
2071 if ( $isnew ) $r .= $N ;
2072 else $r .= '&nbsp;' ;
2073 $r .= '&nbsp;' ; # Minor
2074 if ( $unpatrolled ) {
2075 $r .= "!";
2076 } else {
2077 $r .= "&nbsp;";
2078 }
2079
2080 # Timestamp
2081 $r .= ' '.$block[0]->timestamp.' ' ;
2082 $r .= '</tt>' ;
2083
2084 # Article link
2085 $link = $block[0]->link ;
2086 if ( $block[0]->watched ) $link = '<strong>'.$link.'</strong>' ;
2087 $r .= $link ;
2088
2089 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
2090 if ( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
2091 # Changes
2092 $r .= ' ('.count($block).' ' ;
2093 if ( $isnew ) $r .= wfMsg('changes');
2094 else $r .= $this->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
2095 $curIdEq.'&diff=0&oldid='.$oldid ) ;
2096 $r .= '; ' ;
2097
2098 # History
2099 $r .= $this->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
2100 $r .= ')' ;
2101 }
2102
2103 $r .= $users ;
2104 $r .= "<br />\n" ;
2105
2106 # Sub-entries
2107 $r .= '<div id="'.$rci.'" style="display:none">' ;
2108 foreach ( $block AS $rcObj ) {
2109 # Get rc_xxxx variables
2110 extract( $rcObj->mAttribs );
2111
2112 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
2113 $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;' ;
2114 if ( $rc_new ) {
2115 $r .= $N ;
2116 } else {
2117 $r .= '&nbsp;' ;
2118 }
2119
2120 if ( $rc_minor ) {
2121 $r .= $M ;
2122 } else {
2123 $r .= '&nbsp;' ;
2124 }
2125
2126 if ( $rcObj->unpatrolled ) {
2127 $r .= "!";
2128 } else {
2129 $r .= "&nbsp;";
2130 }
2131
2132 $r .= '&nbsp;</tt>' ;
2133
2134 $o = '' ;
2135 if ( $rc_last_oldid != 0 ) {
2136 $o = 'oldid='.$rc_last_oldid ;
2137 }
2138 if ( $rc_type == RC_LOG ) {
2139 $link = $rcObj->timestamp ;
2140 } else {
2141 $link = $this->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
2142 }
2143 $link = '<tt>'.$link.'</tt>' ;
2144
2145 $r .= $link ;
2146 $r .= ' (' ;
2147 $r .= $rcObj->curlink ;
2148 $r .= '; ' ;
2149 $r .= $rcObj->lastlink ;
2150 $r .= ') . . '.$rcObj->userlink ;
2151 $r .= $rcObj->usertalklink ;
2152 if ( $rc_comment != '' ) {
2153 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2154 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' ) ;
2155 }
2156 $r .= "<br />\n" ;
2157 }
2158 $r .= "</div>\n" ;
2159
2160 $this->rcCacheIndex++ ;
2161 return $r ;
2162 }
2163
2164 /**
2165 * If enhanced RC is in use, this function takes the previously cached
2166 * RC lines, arranges them, and outputs the HTML
2167 */
2168 function recentChangesBlock () {
2169 global $wgStylePath ;
2170 if ( count ( $this->rc_cache ) == 0 ) return '' ;
2171 $blockOut = '';
2172 foreach ( $this->rc_cache AS $secureName => $block ) {
2173 if ( count ( $block ) < 2 ) {
2174 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
2175 } else {
2176 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
2177 }
2178 }
2179
2180 return '<div>'.$blockOut.'</div>' ;
2181 }
2182
2183 /**
2184 * Called in a loop over all displayed RC entries
2185 * Either returns the line, or caches it for later use
2186 */
2187 function recentChangesLine( &$rc, $watched = false ) {
2188 global $wgUser ;
2189 $usenew = $wgUser->getOption( 'usenewrc' );
2190 if ( $usenew )
2191 $line = $this->recentChangesLineNew ( $rc, $watched ) ;
2192 else
2193 $line = $this->recentChangesLineOld ( $rc, $watched ) ;
2194 return $line ;
2195 }
2196
2197 function recentChangesLineOld( &$rc, $watched = false ) {
2198 $fname = 'Skin::recentChangesLineOld';
2199 wfProfileIn( $fname );
2200
2201 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds, $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2202
2203 static $message;
2204 if( !isset( $message ) ) {
2205 foreach( explode(' ', 'diff hist minoreditletter newpageletter blocklink' ) as $msg ) {
2206 $message[$msg] = wfMsg( $msg );
2207 }
2208 }
2209
2210 # Extract DB fields into local scope
2211 extract( $rc->mAttribs );
2212 $curIdEq = 'curid=' . $rc_cur_id;
2213
2214 # Should patrol-related stuff be shown?
2215 $unpatrolled = $wgUseRCPatrol && $wgUser->getID() != 0 &&
2216 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
2217
2218 # Make date header if necessary
2219 $date = $wgLang->date( $rc_timestamp, true);
2220 $s = '';
2221 if ( $date != $this->lastdate ) {
2222 if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
2223 $s .= "<h4>{$date}</h4>\n<ul class=\"special\">";
2224 $this->lastdate = $date;
2225 $this->rclistOpen = true;
2226 }
2227
2228 $s .= '<li>';
2229
2230 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2231 # Diff
2232 $s .= '(' . $message['diff'] . ') (';
2233 # Hist
2234 $s .= $this->makeKnownLinkObj( $rc->getMovedToTitle(), $message['hist'], 'action=history' ) .
2235 ') . . ';
2236
2237 # "[[x]] moved to [[y]]"
2238 $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
2239 $s .= wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2240 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2241 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2242 # Log updates, etc
2243 $logtype = $matches[1];
2244 $logname = LogPage::logName( $logtype );
2245 $s .= '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2246 } else {
2247 wfProfileIn("$fname-page");
2248 # Diff link
2249 if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
2250 $diffLink = $message['diff'];
2251 } else {
2252 if ( $unpatrolled )
2253 $rcidparam = "&rcid={$rc_id}";
2254 else
2255 $rcidparam = "";
2256 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), $message['diff'],
2257 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}{$rcidparam}",
2258 '', '', ' tabindex="'.$rc->counter.'"');
2259 }
2260 $s .= '('.$diffLink.') (';
2261
2262 # History link
2263 $s .= $this->makeKnownLinkObj( $rc->getTitle(), $message['hist'], $curIdEq.'&action=history' );
2264 $s .= ') . . ';
2265
2266 # M, N and ! (minor, new and unpatrolled)
2267 if ( $rc_minor ) { $s .= ' <span class="minor">'.$message["minoreditletter"].'</span>'; }
2268 if ( $rc_type == RC_NEW ) { $s .= '<span class="newpage">'.$message["newpageletter"].'</span>'; }
2269 if ( !$rc_patrolled ) { $s .= ' <span class="unpatrolled">!</span>'; }
2270
2271 # Article link
2272 # If it's a new article, there is no diff link, but if it hasn't been
2273 # patrolled yet, we need to give users a way to do so
2274 if ( $unpatrolled && $rc_type == RC_NEW )
2275 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2276 else
2277 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' );
2278
2279 if ( $watched ) {
2280 $articleLink = '<strong>'.$articleLink.'</strong>';
2281 }
2282 $s .= ' '.$articleLink;
2283 wfProfileOut("$fname-page");
2284 }
2285
2286 wfProfileIn( "$fname-rest" );
2287 # Timestamp
2288 $s .= '; ' . $wgLang->time( $rc_timestamp, true, $wgRCSeconds ) . ' . . ';
2289
2290 # User link (or contributions for unregistered users)
2291 if ( 0 == $rc_user ) {
2292 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
2293 $userLink = $this->makeKnownLinkObj( $contribsPage,
2294 $rc_user_text, 'target=' . $rc_user_text );
2295 } else {
2296 $userPage =& Title::makeTitle( NS_USER, $rc_user_text );
2297 $userLink = $this->makeLinkObj( $userPage, $rc_user_text );
2298 }
2299 $s .= $userLink;
2300
2301 # User talk link
2302 $talkname = $wgContLang->getNsText(NS_TALK); # use the shorter name
2303 global $wgDisableAnonTalk;
2304 if( 0 == $rc_user && $wgDisableAnonTalk ) {
2305 $userTalkLink = '';
2306 } else {
2307 $userTalkPage =& Title::makeTitle( NS_USER_TALK, $rc_user_text );
2308 $userTalkLink= $this->makeLinkObj( $userTalkPage, $talkname );
2309 }
2310 # Block link
2311 $blockLink='';
2312 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2313 $blockLinkPage = Title::makeTitle( NS_SPECIAL, 'Blockip' );
2314 $blockLink = $this->makeKnownLink( $blockLinkPage,
2315 $message['blocklink'], 'ip='.$rc_user_text );
2316
2317 }
2318 if($blockLink) {
2319 if($userTalkLink) $userTalkLink .= ' | ';
2320 $userTalkLink .= $blockLink;
2321 }
2322 if($userTalkLink) $s.=' ('.$userTalkLink.')';
2323
2324 # Add comment
2325 if ( '' != $rc_comment && '*' != $rc_comment && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2326 $rc_comment = $this->formatComment($rc_comment,$rc->getTitle());
2327 $s .= $wgContLang->emphasize(' (' . $rc_comment . ')');
2328 }
2329 $s .= "</li>\n";
2330
2331 wfProfileOut( "$fname-rest" );
2332 wfProfileOut( $fname );
2333 return $s;
2334 }
2335
2336 function recentChangesLineNew( &$baseRC, $watched = false ) {
2337 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds;
2338 global $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2339
2340 static $message;
2341 if( !isset( $message ) ) {
2342 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last blocklink' ) as $msg ) {
2343 $message[$msg] = wfMsg( $msg );
2344 }
2345 }
2346
2347 # Create a specialised object
2348 $rc = RCCacheEntry::newFromParent( $baseRC ) ;
2349
2350 # Extract fields from DB into the function scope (rc_xxxx variables)
2351 extract( $rc->mAttribs );
2352 $curIdEq = 'curid=' . $rc_cur_id;
2353
2354 # If it's a new day, add the headline and flush the cache
2355 $date = $wgLang->date( $rc_timestamp, true);
2356 $ret = '';
2357 if ( $date != $this->lastdate ) {
2358 # Process current cache
2359 $ret = $this->recentChangesBlock () ;
2360 $this->rc_cache = array() ;
2361 $ret .= "<h4>{$date}</h4>\n";
2362 $this->lastdate = $date;
2363 }
2364
2365 # Should patrol-related stuff be shown?
2366 if ( $wgUseRCPatrol && $wgUser->getID() != 0 &&
2367 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') )) {
2368 $rc->unpatrolled = !$rc_patrolled;
2369 } else {
2370 $rc->unpatrolled = false;
2371 }
2372
2373 # Make article link
2374 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2375 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
2376 $clink = wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2377 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2378 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2379 # Log updates, etc
2380 $logtype = $matches[1];
2381 $logname = LogPage::logName( $logtype );
2382 $clink = '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2383 } elseif ( $rc->unpatrolled && $rc_type == RC_NEW ) {
2384 # Unpatrolled new page, give rc_id in query
2385 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2386 } else {
2387 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '' ) ;
2388 }
2389
2390 $time = $wgContLang->time( $rc_timestamp, true, $wgRCSeconds );
2391 $rc->watched = $watched ;
2392 $rc->link = $clink ;
2393 $rc->timestamp = $time;
2394
2395 # Make "cur" and "diff" links
2396 if ( ( $rc_type == RC_NEW && $rc_this_oldid == 0 ) || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2397 $curLink = $message['cur'];
2398 $diffLink = $message['diff'];
2399 } else {
2400 $query = $curIdEq.'&diff=0&oldid='.$rc_this_oldid;
2401 $aprops = ' tabindex="'.$baseRC->counter.'"';
2402 $curLink = $this->makeKnownLinkObj( $rc->getTitle(), $message['cur'], $query, '' ,'' , $aprops );
2403 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), $message['diff'], $query, '' ,'' , $aprops );
2404 }
2405
2406 # Make "last" link
2407 $titleObj = $rc->getTitle();
2408 if ( $rc->unpatrolled ) {
2409 $rcIdQuery = "&rcid={$rc_id}";
2410 } else {
2411 $rcIdQuery = '';
2412 }
2413 if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2414 $lastLink = $message['last'];
2415 } else {
2416 $lastLink = $this->makeKnownLinkObj( $rc->getTitle(), $message['last'],
2417 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
2418 }
2419
2420 # Make user link (or user contributions for unregistered users)
2421 if ( $rc_user == 0 ) {
2422 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
2423 $userLink = $this->makeKnownLinkObj( $contribsPage,
2424 $rc_user_text, 'target=' . $rc_user_text );
2425 } else {
2426 $userPage =& Title::makeTitle( NS_USER, $rc_user_text );
2427 $userLink = $this->makeLinkObj( $userPage, $rc_user_text );
2428 }
2429
2430 $rc->userlink = $userLink;
2431 $rc->lastlink = $lastLink;
2432 $rc->curlink = $curLink;
2433 $rc->difflink = $diffLink;
2434
2435 # Make user talk link
2436 $talkname = $wgContLang->getNsText( NS_TALK ); # use the shorter name
2437 $userTalkPage =& Title::makeTitle( NS_USER_TALK, $rc_user_text );
2438 $userTalkLink = $this->makeLinkObj( $userTalkPage, $talkname );
2439
2440 global $wgDisableAnonTalk;
2441 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2442 $blockPage =& Title::makeTitle( NS_SPECIAL, 'Blockip' );
2443 $blockLink = $this->makeKnownLinkObj( $blockPage,
2444 $message['blocklink'], 'ip='.$rc_user_text );
2445 if( $wgDisableAnonTalk )
2446 $rc->usertalklink = ' ('.$blockLink.')';
2447 else
2448 $rc->usertalklink = ' ('.$userTalkLink.' | '.$blockLink.')';
2449 } else {
2450 if( $wgDisableAnonTalk && ($rc_user == 0) )
2451 $rc->usertalklink = '';
2452 else
2453 $rc->usertalklink = ' ('.$userTalkLink.')';
2454 }
2455
2456 # Put accumulated information into the cache, for later display
2457 # Page moves go on their own line
2458 $title = $rc->getTitle();
2459 $secureName = $title->getPrefixedDBkey();
2460 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2461 # Use an @ character to prevent collision with page names
2462 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
2463 } else {
2464 if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
2465 array_push ( $this->rc_cache[$secureName] , $rc ) ;
2466 }
2467 return $ret;
2468 }
2469
2470 function endImageHistoryList() {
2471 $s = "</ul>\n";
2472 return $s;
2473 }
2474
2475 /**
2476 * This function is called by all recent changes variants, by the page history,
2477 * and by the user contributions list. It is responsible for formatting edit
2478 * comments. It escapes any HTML in the comment, but adds some CSS to format
2479 * auto-generated comments (from section editing) and formats [[wikilinks]].
2480 *
2481 * The &$title parameter must be a title OBJECT. It is used to generate a
2482 * direct link to the section in the autocomment.
2483 * @author Erik Moeller <moeller@scireview.de>
2484 *
2485 * Note: there's not always a title to pass to this function.
2486 * Since you can't set a default parameter for a reference, I've turned it
2487 * temporarily to a value pass. Should be adjusted further. --brion
2488 */
2489 function formatComment($comment, $title = NULL) {
2490 $fname = 'Skin::formatComment';
2491 wfProfileIn( $fname );
2492
2493 global $wgContLang;
2494 $comment = htmlspecialchars( $comment );
2495
2496 # The pattern for autogen comments is / * foo * /, which makes for
2497 # some nasty regex.
2498 # We look for all comments, match any text before and after the comment,
2499 # add a separator where needed and format the comment itself with CSS
2500 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
2501 $pre=$match[1];
2502 $auto=$match[2];
2503 $post=$match[3];
2504 $link='';
2505 if($title) {
2506 $section=$auto;
2507
2508 # This is hackish but should work in most cases.
2509 $section=str_replace('[[','',$section);
2510 $section=str_replace(']]','',$section);
2511 $title->mFragment=$section;
2512 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
2513 }
2514 $sep='-';
2515 $auto=$link.$auto;
2516 if($pre) { $auto = $sep.' '.$auto; }
2517 if($post) { $auto .= ' '.$sep; }
2518 $auto='<span class="autocomment">'.$auto.'</span>';
2519 $comment=$pre.$auto.$post;
2520 }
2521
2522 # format regular and media links - all other wiki formatting
2523 # is ignored
2524 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
2525 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
2526 # Handle link renaming [[foo|text]] will show link as "text"
2527 if( "" != $match[3] ) {
2528 $text = $match[3];
2529 } else {
2530 $text = $match[1];
2531 }
2532 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
2533 # Media link; trail not supported.
2534 $linkRegexp = '/\[\[(.*?)\]\]/';
2535 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
2536 } else {
2537 # Other kind of link
2538 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
2539 $trail = $submatch[1];
2540 } else {
2541 $trail = "";
2542 }
2543 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2544 if ($match[1][0] == ':')
2545 $match[1] = substr($match[1], 1);
2546 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2547 }
2548 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2549 }
2550 wfProfileOut( $fname );
2551 return $comment;
2552 }
2553
2554 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
2555 global $wgUser, $wgLang, $wgContLang, $wgTitle;
2556
2557 $datetime = $wgLang->timeanddate( $timestamp, true );
2558 $del = wfMsg( 'deleteimg' );
2559 $delall = wfMsg( 'deleteimgcompletely' );
2560 $cur = wfMsg( 'cur' );
2561
2562 if ( $iscur ) {
2563 $url = Image::wfImageUrl( $img );
2564 $rlink = $cur;
2565 if ( $wgUser->isAllowed('delete') ) {
2566 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
2567 '&action=delete' );
2568 $style = $this->getInternalLinkAttributes( $link, $delall );
2569
2570 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
2571 } else {
2572 $dlink = $del;
2573 }
2574 } else {
2575 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
2576 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
2577 $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2578 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
2579 urlencode( $img ) );
2580 $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2581 $del, 'action=delete&oldimage=' . urlencode( $img ) );
2582 } else {
2583 # Having live active links for non-logged in users
2584 # means that bots and spiders crawling our site can
2585 # inadvertently change content. Baaaad idea.
2586 $rlink = wfMsg( 'revertimg' );
2587 $dlink = $del;
2588 }
2589 }
2590 if ( 0 == $user ) {
2591 $userlink = $usertext;
2592 } else {
2593 $userlink = $this->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
2594 ':'.$usertext, $usertext );
2595 }
2596 $nbytes = wfMsg( 'nbytes', $size );
2597 $style = $this->getInternalLinkAttributes( $url, $datetime );
2598
2599 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
2600 . " . . {$userlink} ({$nbytes})";
2601
2602 if ( '' != $description && '*' != $description ) {
2603 $sk=$wgUser->getSkin();
2604 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');
2605 }
2606 $s .= "</li>\n";
2607 return $s;
2608 }
2609
2610 function tocIndent($level) {
2611 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2612 }
2613
2614 function tocUnindent($level) {
2615 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2616 }
2617
2618 /**
2619 * parameter level defines if we are on an indentation level
2620 */
2621 function tocLine( $anchor, $tocline, $level ) {
2622 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2623 if($level) {
2624 return $link."\n";
2625 } else {
2626 return '<div class="tocline">'.$link."</div>\n";
2627 }
2628
2629 }
2630
2631 function tocTable($toc) {
2632 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2633 # try min-width & co when somebody gets a chance
2634 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2635 return
2636 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2637 '<b>'.wfMsgForContent('toc').'</b>' .
2638 $hideline .
2639 '</td></tr><tr id="tocinside"><td>'."\n".
2640 $toc."</td></tr></table>\n";
2641 }
2642
2643 /**
2644 * These two do not check for permissions: check $wgTitle->userCanEdit
2645 * before calling them
2646 */
2647 function editSectionScriptForOther( $title, $section, $head ) {
2648 $ttl = Title::newFromText( $title );
2649 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2650 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2651 }
2652
2653 function editSectionScript( $nt, $section, $head ) {
2654 global $wgRequest;
2655 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2656 return $head;
2657 }
2658 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2659 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2660 }
2661
2662 function editSectionLinkForOther( $title, $section ) {
2663 global $wgRequest;
2664 global $wgContLang;
2665
2666 $title = Title::newFromText($title);
2667 $editurl = '&section='.$section;
2668 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2669
2670 if( $wgContLang->isRTL() ) {
2671 $farside = 'left';
2672 $nearside = 'right';
2673 } else {
2674 $farside = 'right';
2675 $nearside = 'left';
2676 }
2677 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2678
2679 }
2680
2681 function editSectionLink( $nt, $section ) {
2682 global $wgRequest;
2683 global $wgContLang;
2684
2685 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2686 # Section edit links would be out of sync on an old page.
2687 # But, if we're diffing to the current page, they'll be
2688 # correct.
2689 return '';
2690 }
2691
2692 $editurl = '&section='.$section;
2693 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2694
2695 if( $wgContLang->isRTL() ) {
2696 $farside = 'left';
2697 $nearside = 'right';
2698 } else {
2699 $farside = 'right';
2700 $nearside = 'left';
2701 }
2702 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2703
2704 }
2705
2706 /**
2707 * This function is called by EditPage.php and shows a bulletin board style
2708 * toolbar for common editing functions. It can be disabled in the user
2709 * preferences.
2710 * The necessary JavaScript code can be found in style/wikibits.js.
2711 */
2712 function getEditToolbar() {
2713 global $wgStylePath, $wgLang, $wgMimeType;
2714
2715 /**
2716 * toolarray an array of arrays which each include the filename of
2717 * the button image (without path), the opening tag, the closing tag,
2718 * and optionally a sample text that is inserted between the two when no
2719 * selection is highlighted.
2720 * The tip text is shown when the user moves the mouse over the button.
2721 *
2722 * Already here are accesskeys (key), which are not used yet until someone
2723 * can figure out a way to make them work in IE. However, we should make
2724 * sure these keys are not defined on the edit page.
2725 */
2726 $toolarray=array(
2727 array( 'image'=>'button_bold.png',
2728 'open' => "\'\'\'",
2729 'close' => "\'\'\'",
2730 'sample'=> wfMsg('bold_sample'),
2731 'tip' => wfMsg('bold_tip'),
2732 'key' => 'B'
2733 ),
2734 array( 'image'=>'button_italic.png',
2735 'open' => "\'\'",
2736 'close' => "\'\'",
2737 'sample'=> wfMsg('italic_sample'),
2738 'tip' => wfMsg('italic_tip'),
2739 'key' => 'I'
2740 ),
2741 array( 'image'=>'button_link.png',
2742 'open' => '[[',
2743 'close' => ']]',
2744 'sample'=> wfMsg('link_sample'),
2745 'tip' => wfMsg('link_tip'),
2746 'key' => 'L'
2747 ),
2748 array( 'image'=>'button_extlink.png',
2749 'open' => '[',
2750 'close' => ']',
2751 'sample'=> wfMsg('extlink_sample'),
2752 'tip' => wfMsg('extlink_tip'),
2753 'key' => 'X'
2754 ),
2755 array( 'image'=>'button_headline.png',
2756 'open' => "\\n== ",
2757 'close' => " ==\\n",
2758 'sample'=> wfMsg('headline_sample'),
2759 'tip' => wfMsg('headline_tip'),
2760 'key' => 'H'
2761 ),
2762 array( 'image'=>'button_image.png',
2763 'open' => '[['.$wgLang->getNsText(NS_IMAGE).":",
2764 'close' => ']]',
2765 'sample'=> wfMsg('image_sample'),
2766 'tip' => wfMsg('image_tip'),
2767 'key' => 'D'
2768 ),
2769 array( 'image' => 'button_media.png',
2770 'open' => '[['.$wgLang->getNsText(NS_MEDIA).':',
2771 'close' => ']]',
2772 'sample'=> wfMsg('media_sample'),
2773 'tip' => wfMsg('media_tip'),
2774 'key' => 'M'
2775 ),
2776 array( 'image' => 'button_math.png',
2777 'open' => "\\<math\\>",
2778 'close' => "\\</math\\>",
2779 'sample'=> wfMsg('math_sample'),
2780 'tip' => wfMsg('math_tip'),
2781 'key' => 'C'
2782 ),
2783 array( 'image' => 'button_nowiki.png',
2784 'open' => "\\<nowiki\\>",
2785 'close' => "\\</nowiki\\>",
2786 'sample'=> wfMsg('nowiki_sample'),
2787 'tip' => wfMsg('nowiki_tip'),
2788 'key' => 'N'
2789 ),
2790 array( 'image' => 'button_sig.png',
2791 'open' => '--~~~~',
2792 'close' => '',
2793 'sample'=> '',
2794 'tip' => wfMsg('sig_tip'),
2795 'key' => 'Y'
2796 ),
2797 array( 'image' => 'button_hr.png',
2798 'open' => "\\n----\\n",
2799 'close' => '',
2800 'sample'=> '',
2801 'tip' => wfMsg('hr_tip'),
2802 'key' => 'R'
2803 )
2804 );
2805 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
2806
2807 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
2808 foreach($toolarray as $tool) {
2809
2810 $image=$wgStylePath.'/common/images/'.$tool['image'];
2811 $open=$tool['open'];
2812 $close=$tool['close'];
2813 $sample = addslashes( $tool['sample'] );
2814
2815 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2816 // Older browsers show a "speedtip" type message only for ALT.
2817 // Ideally these should be different, realistically they
2818 // probably don't need to be.
2819 $tip = addslashes( $tool['tip'] );
2820
2821 #$key = $tool["key"];
2822
2823 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
2824 }
2825
2826 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
2827 $toolbar.="document.writeln(\"</div>\");\n";
2828
2829 $toolbar.="/*]]>*/\n</script>";
2830 return $toolbar;
2831 }
2832
2833 /**
2834 * @access public
2835 */
2836 function suppressUrlExpansion() {
2837 return false;
2838 }
2839 }
2840
2841 }
2842 ?>